﻿#ifndef SALEMODEL_H
#define SALEMODEL_H

#include <QStandardItemModel>
#include "excelimportthread.h"
#include "excelexportthread.h"
#include "qprintermanager.h"
#include "userrelation.h"
#include "product.h"
#include "dingdandetail.h"
#include "historyproduct.h"

class SaleModel : public QStandardItemModel
{
    Q_OBJECT
public:
    explicit SaleModel(QObject *parent = nullptr);

    QStringList header;

    bool setData(const QModelIndex &index, const QVariant &value, int role) override;

    QVariant data(const QModelIndex &index, int role) const override;

    void setWidgetType(UserRelation::RelationType widgetType);

    void insertProduct(int insertRowIndex, Product &product, int defaultCount);

    void insertProduct(int startIndex, QList<Product*> products, int defaultCount);

    void insertDingdanDetail(DingdanDetail &detail);

    void insertDingdanDetail(QList<DingdanDetail*> details);

    void updateProductPrice(QList<HistoryProduct*> historyProducts);

    void removeRowData(int row);

    void refresh();

    void reset();

    QList<DingdanDetail*> currentDingdanDetails();

    //从Excel导入数据
    void importDataFromExcel(QString fileName);
    //导出数据到Excel
    void exportDataToExcel(QString fileName);
    //更新数据
    void updateData(QList<QList<QVariant>> data);
    //获取导出数据
    QList<QList<QVariant>> getExportData();


signals:
    void updateTotal(int, double);

    void importDataDone();

    void exportDataDone();

public slots:

private:
    ExcelImportThread importThread;
    ExcelExportThread exportThread;

    UserRelation::RelationType widgetType;
    QList<DingdanDetail*> dingdanDetails;
    QList<Product*> products;
};

#endif // SALEMODEL_H
